package com.readytocloud.r2cSoonSite;

import java.io.IOException;
import javax.servlet.http.*;

import com.google.appengine.api.quota.QuotaService;
import com.google.appengine.api.quota.QuotaServiceFactory;

import java.util.logging.Logger;

@SuppressWarnings("serial")
public class R2CComingSoonSiteServlet extends HttpServlet {
	
	private static final Logger log = Logger.getLogger(R2CComingSoonSiteServlet.class.getName());
	
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		//The two lines below will get the CPU before requesting User-Agent Information
		QuotaService qs = QuotaServiceFactory.getQuotaService();
		long start = qs.getCpuTimeInMegaCycles();
		
		//Request the user Agent info
		String userAgent = req.getHeader("User-Agent");
		
		//The three lines below will get the CPU after requesting User-Agent Information 
		// and informed it to the application log.
		long end = qs.getCpuTimeInMegaCycles();
		double cpuSeconds = qs.convertMegacyclesToCpuSeconds(end - start);
		log.warning("CPU Seconds on geting User Agent: " + cpuSeconds);
		
		userAgent = userAgent.toLowerCase();
		if(userAgent.contains("iphone"))
			resp.sendRedirect("/mobIndex.html");
		else
			resp.sendRedirect("/index.html");
	}
	
}
